﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.ComponentModel;

using EasyProp.Extensions;
using Castle.Core.Interceptor;

namespace EasyProp
{
    public class DoNothingIfValueNotChanged : IPropertySetterFilter
    {
        #region IPropertySetterFilter Members

        public bool Execute(IInvocation invocation, string propertyName)
        {
            if (invocation.Arguments == null || invocation.Arguments.Count() == 0) return true;

            object argument = invocation.Arguments[0];
            return (invocation.TargetType.GetProperty(propertyName).GetValue(invocation.InvocationTarget, null) != argument);
        }

        #endregion
    }
}
